<div data-ng-controller="contractPerformanceCtrl">
    <div class="table-header clearfix ng-scope">
        <span class="fl lh30 f14">{{contractBaseInfo.contract_code}}</span>
    </div>

    <form class="form-horizontal" name="contractPerformanceForm">
        <div class="form-group mt10">
            <!--<span for="inputtext3" class="col-sm-3 control-label">合同成交折扣(%) :</span>-->

            <!--<div class="col-sm-5">-->
            <!--<input type="number" class="form-control" ng-value="contractPfmInfo.contract_deal_discount|percent|number:0"-->
            <!--placeholder="合同成交折扣" disabled>-->
            <!--</div>-->
            <span for="inputtext3" class="col-sm-3 control-label">产品数:</span>

            <div class="col-sm-5">
                <input type="number" class="form-control" ng-model="contractPfmInfo.draw_project_numeric"
                       placeholder="提成产品数">
            </div>
            <span for="inputtext3" class="col-sm-3 control-label">项目数:</span>

            <div class="col-sm-5">
                <input type="number" class="form-control" ng-model="contractPfmInfo.project_numeric"
                       placeholder="项目数">
            </div>
        </div>

        <div class="form-group mt10">
            <span class="col-sm-3 control-label">备注:</span>
            <div class="col-sm-21">
                <textarea name="achievement_remark" id="" class="form-control" rows="3" ng-model="contractBaseInfo.achievement_remark" ng-maxlength="500"></textarea>
                <span role="alert"
                      ng-show="(contractPerformanceForm.$submitted || contractPerformanceForm.achievement_remark.$touched) && contractPerformanceForm.achievement_remark.$error.maxlength"
                      class="error ng-hide c-red lh30">备注信息不能超过500个字符</span>
            </div>
        </div>

        <div class="mt20 clearfix ng-scope ml25">
            <span class="fl lh30 f14">签约业绩</span>
        </div>
        <div class="table-wrap mt10 ml25" style="min-height: 200px;overflow: visible">

            <table width="100%" class="valign-t">
                <thead>
                <tr>
                    <th style="width: 35px;">序号</th>
                    <th ng-repeat="attribute_name in attribute_name_text" style="width: 30px;" class="align-m">{{attribute_name}}</th>
                    <th style="width: 80px;" class="align-r">签约业绩金额</th>
                    <th style="width: 90px;" class="align-m">业绩归属时间</th>
                    <th style="width: 190px;">业绩归属信息</th>
                    <th style="width: 190px;">ERP业绩归属信息</th>
                    <th style="width: 130px;">ERP业绩归属客户经理</th>
                    <th style="width: 120px;">ERP业绩归属部门</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr ng-repeat="record in contractPfmInfo.signAchievements" ng-if="record.__type != 'delete'"
                    style="line-height: 35px;">
                    <td><p ng-bind="$index + 1"></p></td>

                    <td ng-repeat="text in attribute_name_text" class="align-m">
                        <input type="checkbox" ng-disabled="(record.editMode || 0) == 0" ng-model="record.attribute_name[$index]" ng-true-value='"true"'  ng-false-value='"false"' >
                    </td>

                    <td class="align-r">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="record.achievement_amount | number:2"></p>

                        <p ng-if="(record.editMode || 0) != 0">
                            <input type="text" ng-model="record.achievement_amount" class="form-control"
                                   placeholder="签约业绩金额">
                        </p>
                    </td>
                    <td class="align-m">
                        <p ng-bind="record.achievement_belong_time|strdate:'yyyy-MM-dd'"></p>
                    </td>
                    <td style="line-height: 27px;">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'归属人：'+record.belong_name"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">归属人：
                            <input name="belong_by" select2 ng-model="record.belong_by" style="position: absolute;top: 0;width: 146px;right: 0;"
                                   select2-model="record.ddl2BelongBy" data="record"
                                   config="ddlConfigBelongBy" type="text" placeholder="业绩归属人"
                                   class="form-control idBelongBy1">
                        </p>
                        <p ng-bind="'归属部门：'+record.department_name"></p>
                        <p ng-bind="'归属区域：'+record.area_name"></p>
                    </td>
                    <td style="line-height: 27px;">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'归属人：'+record.erp_achievement_belong_name"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">归属人：
                            <input name="belong_by" select2 ng-model="record.erp_achievement_belong" style="position: absolute;top: 0;width: 146px;right: 0;"
                                   select2-model="record.ddl2BelongBy" data="record"
                                   config="ddlConfigErpBelongBy" type="text" placeholder="ERP业绩归属人"
                                   class="form-control idErpBelongBy">
                        </p>
                        <p ng-bind="'归属ABU：'+record.erp_achievement_belong_abu_name"></p>
                        <p ng-bind="'归属ABU负责人：'+record.erp_achievement_belong_abu_owner_name"></p>
                        <p ng-bind="'归属部门经理：'+record.erp_achievement_belong_bu_manager_name"></p>
                    </td>

                    <td>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="record.manager_name || null"></p>

                        <p ng-if="(record.editMode || 0) != 0">
                            <input name="manager_by" select2 ng-model="record.manager_by"
                                   select2-model="record.ddl2ManagerBy" data="record"
                                   config="ddlConfigManagerBy" type="text" placeholder="ERP客户经理"
                                   class="form-control idManagerBy1">
                        </p>
                    </td>
                    <td>
                        <p ng-bind="record.erp_achievement_belong_bu_name"></p>
                    </td>
                    <td>
                        <div row-toolbar min-buttons-show="3"
                             ng-if="contractBaseInfo.is_cancelled == 0 && userAuthList.indexOf('0001') !== -1">
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="拆分业绩信息"
                               ng-click="addSignAchievement(contractPfmInfo.signAchievements,record)">拆分</a>
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="修改业绩信息"
                               ng-click="editSignAchievement(record, $index,contractPfmInfo.signAchievements)">修改</a>
                            <a ng-if="(record.editMode || 0)  == 0 && contractPfmInfo.signAchievements.length>1"
                               ng-click="delSignAchievement(record,$index,contractPfmInfo.signAchievements)"
                               href="javascript:void(0)"
                               title="删除业绩信息">删除</a>

                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="保存业绩信息"
                               ng-click="saveSignAchievement(record)">确定</a>
                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="取消修改业绩信息"
                               ng-click="cancelSignAchievement(record, $index,contractPfmInfo.signAchievements)">取消</a>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="no-data" ng-if="contractPfmInfo.signAchievements.length == 0"><span>暂无数据</span></div>
        </div>
        <!--remark-->
        <div class="mt10 ml25">
            <span class="pl10">说明：{{contractBaseInfo|signOrBalanceLabel}}(<em class="b">{{contractBaseInfo|signOrBalanceAmount|number:2}}</em>元)
            = 已确定业绩（<em class="b">{{contractPfmInfo.signAchievements|sumSignAmount|number:2}}</em>元） + 待确定业绩（<em
                        class="b c-red">{{contractPfmInfo.signAchievements|remainSignAmount:contractBaseInfo|number:2}}</em>元）
            </span>
        </div>

        <div class="mt20 clearfix ng-scope ml25">
            <span class="fl lh30 f14">回款业绩</span>
        </div>
        <div class="table-wrap mt10 ml25" style="min-height: 200px;overflow: visible">

            <table width="100%" class="valign-t">
                <thead>
                <tr>
                    <th style="width: 35px;">序号</th>
                    <th ng-repeat="attribute_name in attribute_name_text" style="width: 30px;" class="align-m">{{attribute_name}}</th>
                    <th style="width: 120px;">款项信息</th>
                    <th style="width: 80px;">回款业绩金额</th>
                    <th style="width: 100px;">实收时间</th>
                    <th style="width: 190px;">业绩归属信息</th>
                    <th style="width: 190px;">ERP业绩归属信息</th>
                    <th style="width: 140px;">ERP业绩归属客户经理</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr ng-repeat="record in contractPfmInfo.paymentAchievement"
                    ng-if="record.__type != 'delete'"
                    style="line-height: 35px;">
                    <td style="text-align: center;"><p ng-bind="$index + 1"></p></td>
                    <td ng-repeat="text in attribute_name_text" class="align-m">
                        <input type="checkbox" ng-disabled="(record.editMode || 0) == 0" ng-model="record.attribute_name[$index]" ng-true-value='"true"' ng-false-value='"false"' >
                    </td>
                    <td>
                        <p ng-bind="'名称：'+record.receivable_item_name"></p>
                        <p ng-bind="'小类：'+record.money_category_item_name"></p>
                    </td>
                    <td>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="record.achievement_amount | number:2"></p>

                        <p ng-if="(record.editMode || 0) != 0">
                            <input type="text" ng-model="record.achievement_amount" class="form-control"
                                   placeholder="回款业绩金额">
                        </p>
                    </td>
                    <td>
                        <p ng-bind="record.received_time|strdate:'yyyy-MM-dd'"></p>
                    </td>
                    <td>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'归属人：'+record.belong_name"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">归属人：
                            <input name="belong_by" select2 ng-model="record.belong_by" style="position: absolute;top: 0;width: 146px;right: 0;"
                                   select2-model="record.ddl2BelongBy" data="record"
                                   config="ddlConfigBelongBy" type="text" placeholder="业绩归属人"
                                   class="form-control idBelongBy2">
                        </p>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'归属时间：'+(record.achievement_belong_time|strdate:'yyyy-MM-dd')"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">归属时间：
                            <input type="text" class="input-date fl form-control" style="position: absolute;top: 0;width: 136px;right: 0;"
                                   ui-date format="yyyy-MM-dd" ng-model="record.achievement_belong_time" placeholder="业绩归属时间">
                        </p>

                        <p ng-bind="'归属部门：'+record.department_name"></p>
                        <p ng-bind="'归属区域：'+record.area_name"></p>
                    </td>
                    <td style="line-height: 27px;">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'归属人：'+record.erp_achievement_belong_name"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">归属人：
                            <input name="belong_by" select2 ng-model="record.erp_achievement_belong" style="position: absolute;top: 0;width: 146px;right: 0;"
                                   select2-model="record.ddl2BelongBy" data="record"
                                   config="ddlConfigErpBelongBy" type="text" placeholder="ERP业绩归属人"
                                   class="form-control idErpBelongBy">
                        </p>
                        <p ng-bind="'归属ABU：'+record.erp_achievement_belong_abu_name"></p>
                        <p ng-bind="'归属ABU负责人：'+record.erp_achievement_belong_abu_owner_name"></p>
                        <p ng-bind="'归属部门经理：'+record.erp_achievement_belong_bu_manager_name"></p>
                    </td>

                    <td>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'客户经理：'+record.manager_name || null"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">客户经理：
                            <input name="manager_by" select2 ng-model="record.manager_by" style="position: absolute;top: 0;width: 137px;right: 0;"
                                   select2-model="record.ddl2ManagerBy" data="record"
                                   config="ddlConfigManagerBy" type="text" placeholder="ERP客户经理"
                                   class="form-control idManagerBy2">
                        </p>
                        <p ng-bind="'归属部门：'+record.erp_achievement_belong_bu_name"></p>

                    </td>
                    <td>

                        <div row-toolbar min-buttons-show="3"
                             ng-if="contractBaseInfo.contract_status == 2 && contractBaseInfo.is_cancelled == 0 && userAuthList.indexOf('0001') !== -1">
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="拆分业绩信息"
                               ng-click="addSignAchievement(contractPfmInfo.paymentAchievement,record)">拆分</a>
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="修改业绩信息"
                               ng-click="editSignAchievement(record, $index,contractPfmInfo.paymentAchievement)">修改</a>
                            <a ng-if="(record.editMode || 0)  == 0 && contractPfmInfo.paymentAchievement.length>1"
                               ng-click="delSignAchievement(record,$index,contractPfmInfo.paymentAchievement)"
                               href="javascript:void(0)"
                               title="删除业绩信息">删除</a>

                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="保存业绩信息"
                               ng-click="saveSignAchievement(record)">确定</a>
                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="取消修改业绩信息"
                               ng-click="cancelSignAchievement(record, $index,contractPfmInfo.paymentAchievement)">取消</a>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="no-data" ng-if="contractPfmInfo.paymentAchievement.length == 0" style="height:180px">
                <span>暂无数据</span></div>
        </div>
        <div class="mt10 ml25">
            <span class="pl10">说明：回款信息总额:(<em class="b">{{receivableInfo.payments|sumBackAmountP|number:2}}</em>元)
            = 已确定业绩（<em class="b">{{contractPfmInfo.paymentAchievement|sumPaymentAmountP|number:2}}</em>元） + 待确定业绩（<em
                        class="b c-red">{{contractPfmInfo.paymentAchievement|remainPaymentAmountP:receivableInfo.payments|number:2}}</em>元）
            </span>
        </div>

        <div class="form-group" ng-if="!areaRole">
            <div class="ml35 mt15">
                <button type="button"
                        ng-click="contractPerformanceForm.$valid && save() "
                        class="btn btn-default"
                        ng-disabled="saveEnabled()"
                        ng-if="contractBaseInfo.is_cancelled == 0 && userAuthList.indexOf('0001') !== -1">
                    保存
                </button>
            </div>
        </div>
    </form>
</div>